import dayjs from 'dayjs'

// 时间转换
export function useTimeFormat(
  initialTime = new Date(),
  initialFormat = 'YYYY-MM-DD HH:mm:ss'
) {
  const formattedTime = dayjs(initialTime).format(initialFormat)

  const updateTime = (newTime, newFormat = initialFormat) => {
    if (newTime) return dayjs(newTime).format(newFormat)
    else return ''
  }

  return {
    formattedTime,
    updateTime,
  }
}
